package com.BlogPark.service.LoginService.Impl;

import com.BlogPark.common.utis.MD5Utils;
import com.BlogPark.controller.result.Result;
import com.BlogPark.mapper.UserMapper;
import com.BlogPark.pojo.User;
import com.BlogPark.service.LoginService.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.BlogPark.controller.exception.Code.GET_OK;

/**
 * @Auther: MFM
 * @Date: 2022/8/10 - 08 - 10 - 21:13
 * @version: 1.0
 */

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UserMapper userMapper;


    /**
     * 登出
     * @param email
     * @return
     */
    @Override
    public int statusOn(String email) {
        return userMapper.statusOn(email);
    }

    /**
     * 登出
     * @param email
     * @return
     */
    @Override
    public int statusOff(String email) {
        return userMapper.statusOff(email);
    }

    /**
     * 登录
     *
     * @param user
     * @return
     */
    @Override
    public User Login(User user) {
        String md5pwd = MD5Utils.getMd5(user.getPassword());
        User loginUser = userMapper.Login(user.getUsername(), md5pwd);
        return loginUser;
    }

    /**
     * 找回密码byEmail
     *
     * @param email
     * @return
     */
    @Override
    public User getUserByEmail(String email) {
        return userMapper.selectUserByEmail(email);
    }


    /**
     * 修改密码或用户名
     *
     * @param user
     */
    @Override
    public int updateUser(User user) {
        int i = userMapper.updateUser(user);
        return i;
    }

    /**
     * findUserByEmail
     *
     * @param email
     * @return
     */
    @Override
    public User findUserByEmail(String email) {
        User user = userMapper.selectUserByEmail(email);
        return user;
    }




    public int updatePWD(User user) {
        return userMapper.AddUserOrUpdatePWD(user);
    }


}
